import { NestFactory } from '@nestjs/core';
import { ValidationPipe } from '@nestjs/common';

import { AppModule } from './app.module';
import { TransformInterceptor } from './core/interceptor/transform.interceptor';
import { HttpExceptionFilter } from './core/filter/http-exception.filter';
import { setupSwagger } from './setup-swagger'
import { ConfigService } from '@nestjs/config'
import type { ConfigKeyPaths } from './config'
async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  // 全局注册拦截器
  app.useGlobalInterceptors(new TransformInterceptor());
  // 全局注册异常过滤器
  app.useGlobalFilters(new HttpExceptionFilter());
  // 全局注册验证管道
  app.useGlobalPipes(new ValidationPipe());

  // 使用configService 配置api 文档
  const configService = app.get(ConfigService<ConfigKeyPaths>)
  const { port, globalPrefix } = configService.get('app', { infer: true })
  setupSwagger(app, configService)

  await app.listen(port);


}
bootstrap();
